package leetcode.slidwidow;

public class Lc1456 {

    public int maxVowels(String s, int k) {

        int ans = 0;
        for (int i = 0; i < k && i < s.length(); i++) {
            if (isVowel(s.charAt(i)))
                ans++;
        }
        int i = 0, j = k -1, cnt = ans;
        while (i <= j && j < s.length()) { //始终维护一个长为k的窗口
            if (cnt == k) return k;
            if (i < s.length() && isVowel(s.charAt(i)))
                cnt--;
            i++;
            j++;
            if (j < s.length() && isVowel(s.charAt(j))) {
                cnt++;
                ans = ans < cnt ? cnt : ans;
            }
        }
        return ans;
    }
    public boolean isVowel(char c) {
        if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
            return true;
        return false;
    }

    public static void main(String[] args) {
        Lc1456 lc1456 = new Lc1456();
        System.out.println(lc1456.maxVowels("tnfazcwrryitgacaabwm", 7));
    }
}
